import axios from './ajax';
import type { RESDataType } from './ajax';

type SearchOptions = {
  keyword?: string;
  isStar?: boolean;
  isDeleted?: boolean;
  page?: number;
  pageSize?: number;
};

// 获取单个问卷信息
export async function getQuestionList(id: string): Promise<RESDataType> {
  const res = await axios.get(`/api/question/${id}`);
  return res;
}

// 创建问卷
export async function createQuestion(): Promise<RESDataType> {
  const res = await axios.post('/api/question');
  return res;
}

// 查询问卷列表
export async function getAllQuestionList(
  opt: Partial<SearchOptions> = {}
): Promise<RESDataType> {
  const res = await axios.get('/api/question', { params: opt });
  return res;
}

// 更新问卷
export async function updateQuestionList(
  id: string,
  data: { [key: string]: any }
): Promise<RESDataType> {
  const res = await axios.patch(`/api/question/${id}`, { params: data });
  return res;
}

// 复制问卷
export async function copyQuestionList(id: string): Promise<RESDataType> {
  const res = await axios.post(`/api/question/duplicate/${id}`);
  return res;
}

// 批量彻底删除
export async function deleteQuestionList(ids: string[]): Promise<RESDataType> {
  const res = await axios.delete('/api/question', { data: ids });
  return res;
}
